Skip to content

grafana/k6-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Open source load testing tool and SaaS for ambitious engineering teams.

Get started

It's as easy as:

Local test

name: Main Workflow
on: [push]
jobs:
  build:
    name: Run k6 test
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Run k6 local test
        uses: grafana/k6-action@v0.3.1
        with:
          filename: my-load-test.js
          flags: --vus 50 --duration 10s

Cloud test

name: Main Workflow
on: [push]
jobs:
  build:
    name: Run k6 test
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Run k6 cloud test
        uses: grafana/k6-action@v0.3.1
        with:
          filename: my-load-test.js
          flags: --vus 50 --duration 10s
          cloud: true
          token: ${{ secrets.K6_CLOUD_API_TOKEN }}

Inputs

Filename

steps:
  - name: Run k6 local test
    uses: grafana/k6-action@v0.3.1
    with:
      filename: my-script-file.js

Sets the filename of the test script to execute. This property is relative to the workspace directory. If omitted, it defaults to test.js.

Cloud

environment: test

steps:
  - name: Run k6 cloud test
    uses: grafana/k6-action@v0.3.1
    with:
      cloud: true
      token: ${{ secrets.K6_CLOUD_API_TOKEN }}

Enables execution in Grafana Cloud k6. Additional details on the k6 cloud offering are available at https://grafana.com/docs/grafana-cloud/k6/.

You can use a Grafana Cloud k6 personal API token, or a Grafana Stack API token. For more details, refer to Authenticate on the CLI.

Flags

steps:
  - name: Run k6 local test
    uses: grafana/k6-action@v0.3.1
    with:
      flags: --vus 50 --duration 10s

Any additional arguments or flags to pass to the k6 CLI. The full list of possible options is available at https://grafana.com/docs/k6/latest/using-k6/k6-options/reference/.

For additional information, and help getting started, see https://grafana.com/docs/k6/latest/get-started/running-k6/.

Environment Variables

Environment variables can be added the same way as you do it locally, using the flags action option:

steps:
  - name: Run k6 local test
    uses: grafana/k6-action@v0.3.1
    with:
      filename: my-script-file.js
      flags: --env MY_VAR=42

Or can be scoped to the action step:

steps:
  - name: Run k6 local test
    uses: grafana/k6-action@v0.3.1
    with:
      filename: my-script-file.js
    env:
      MY_VAR: 42

Side-by-side with the System under Test

You might want to host the system under test (SUT) within the workflow for testing. If you have dockerized your application or SUT, you can use service containers to make it available for testing within the same job.

The following example runs the application on port 3333. It passes the URL of the SUT as an environment variable to the k6 test and then runs the test.

name: Testing QuickPizza
on: push

jobs:
  runner-job:
    runs-on: ubuntu-latest

    services:
      quickpizza:
        image: ghcr.io/grafana/quickpizza-local:0.4.0
        ports:
          - 3333:3333
          
    steps:
      - name: Checkout
        uses: actions/checkout@v4
  
      - name: Run local k6 test
        uses: grafana/k6-action@v0.3.1
        with:
          filename: script.js
        env:
          BASE_URL: "http://quickpizza:3333"

For non-Dockerized apps, you can download the k6 binary and run the k6 test from the same step as the app starts:

name: Main Workflow
on: [push]
jobs:
  build:
    name: Run k6 test
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install k6
        run: |
          curl https://github.com/grafana/k6/releases/download/v0.47.0/k6-v0.47.0-linux-amd64.tar.gz -L | tar xvz --strip-components 1
      - name: Install packages
        run: |
          npm install
      - name: Start server and run tests
        run: |
          npm start & npx wait-on http://localhost:3000
          ./k6 run test.js

Thanks to Amy Hoad for contributing on the solution for this.